<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Bootstrap core CSS -->
    <link th:href="@{../asserts/css/bootstrap.min.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link th:href="@{../asserts/css/dashboard.css}" rel="stylesheet">
    <style type="text/css">
        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }

        .hidden {
            display: none !important;
        }
    </style>
</head>

<body>
<div th:replace="commons/bar::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/bar::sidebar(activeUri='goodsDiscountInfos')"></div>
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <th:block th:if="${goodsDiscountInfo ne null}">
                <h2>Изменить</h2>
            </th:block>
            <th:block th:if="${goodsDiscountInfo eq null}">
                <h2>Добавить</h2>
            </th:block>
            <form th:action="@{/goodsDiscountInfo}" method="post">
                <input type="hidden" name="_method" value="put" th:if="${goodsDiscountInfo ne null}">
                <div class="form-group">
                    <th:block th:if="${goodsDiscountInfo eq null}">
                    <label for="goodsBarCode">Товарный штрих-код</label>
                    <select id="goodsBarCode" class="form-control" name="goodsBarCode" onchange="getGoodsName()">
                            <option>Выбирать...</option>
                            <option th:each="goods : ${goods}" th:text="${goods.goodsBarCode}"
                                    th:value="${goods.goodsBarCode}"></option>
                    </select>
                    </th:block>
                    <th:block th:if="${goodsDiscountInfo ne null}">
                        <label for="goodsBarCode2" hidden>Товарный штрих-код</label>
                        <select id="goodsBarCode2" class="form-control" name="goodsBarCode" hidden>
                            <option>Выбирать...</option>
                            <option th:each="goods : ${goods}" th:text="${goods.goodsBarCode}"
                                    th:value="${goods.goodsBarCode}" th:selected="${goodsDiscountInfo ne null}?${goodsDiscountInfo.goodsBarCode eq goods.goodsBarCode}"></option>
                        </select>
                    </th:block>
                </div>
                <div class="form-group">
                    <label for="goodsName">Наименование товара</label>
                    <input type="text" class="form-control" id="goodsName" name="goodsName" th:value="${goodsDiscountInfo ne null}?${goodsDiscountInfo.goodsName}" disabled>
                </div>
                <div class="form-group">
                    <label for="goodsDiscount">Товар со скидкой</label>
                    <input type="text" class="form-control" id="goodsDiscount" name="goodsDiscount" th:value="${goodsDiscountInfo ne null}?${goodsDiscountInfo.goodsDiscount}" required>
                </div>
                <div class="form-group">
                    <input type="submit" class="btn btn-primary" value="Разместить" onclick="change()">
                </div>
            </form>
        </main>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="../../asserts/js/jquery-3.2.1.slim.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript" src="../asserts/js/popper.min.js"></script>
<script type="text/javascript" src="../asserts/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../asserts/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="../asserts/js/locales/bootstrap-datetimepicker.ru.js"></script>

<!-- Icons -->
<script type="text/javascript" src="../asserts/js/feather.min.js"></script>
<script>
    feather.replace()
</script>

<!-- Graphs -->
<script type="text/javascript" src="../asserts/js/Chart.min.js"></script>

<script th:inline="javascript">
    function getGoodsName() {
        $.ajax({
            type:'GET',
            url:'goods',
            data:{
                'goodsBarCode':$('#goodsBarCode option:selected').val()
            },
            contentType: "application/json;charset=utf-8",
            success:function(data) {
                $('#goodsName').val(data['goodsName']);
            }
        })
    }
</script>
<script>
    function change() {
        $('#goodsBarCode2').removeAttr("disabled");
    }
</script>

</body>

</html>